/** @file GOTHspi.c This file contains the source code for the SPI API of the GOTH
 * Kick-ass Etherboard.
 * 
 * Basic layer for SPI on the Kick-ass Etherboard. This file sets the SPI2-port to a clock of 4 MHz.
 * SPI2 is used for the MAC-EEPROM on the board and an extra peripheral that can be added later on.
 *
 * Keep in mind that, in order to use the EEPROM or the extra peripheral, you also need:
 * For EEPROM:
 *		- GOTHspiEeprom.c
 *		- GOTHspiEeprom.h
 * For the extra peripheral:
 *		- GOTHspiExtra.c
 *		- GOTHspiExtra.h
 *
 *
 * @author Geoffrey Ottoy - Tom Hamelinckx
 * @date 05/07/2011 (last modified)
 *
 * <pre>
 * MODIFICATION HISTORY:
 *
 * Who  Date     Changes
 * ---- -------- ---------------------------------------------------------
 * TH   02/07/11 Created this file.
 * TH   04/07/11 Changed to new API-style (split into 3 (spi, eeprom and extra)
 * TH   05/07/11 Documented and tested
 * </pre>
 * 
 */
#ifndef __GOTH_SPI_H__
#define __GOTH_SPI_H__

#include "p24fj256GB110.h"
#include "GOTHglobal.h"


#define SPI_DisableEeprom() {SPI2STATbits.SPIEN = 0;}
#define SPI_EnableEeprom()  {SPI2STATbits.SPIEN = 1;}

/** Initialize SPI2 for operation.
 * 
 * @return	nothing
 *
 * @warning Attached memory has a maximum allowed clock of 5 MHz! Do not exceed!
 */
void SPI_InitSpi2(void); 

/** Send data to the selected SPI2 device and read back its answer.
 * 
 * To keep clocking the device and just waiting for its response, keep sending 0
 *
 * @param	data	One byte of data to send out
 *
 * @return	The response from the readback
 */
unsigned char SPI_TransmitReceive(unsigned char data);

 
 
 
#endif

